package com.expense.services;

import java.lang.reflect.Field;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import com.expense.dao.Dao;
import com.expense.entity.UserInfo;
import com.expense.util.PaginatedList;

/**
 * 用户信息 Services类
 * @author xj
 * */
public class UserInfoServices extends BasicServices {
	
	/**
	 * 用户登陆
	 * */
	public String userLogin(String loginName,String passWord,HttpServletRequest request){
		String strValue="";
		HttpSession session=request.getSession();
		Dao dao=new Dao();
		if (dao.getConn()!=null) {
			String tableName=this.getTableName(UserInfo.class);
			
			String sql="select * from "+tableName+" where LOGINNAME='"+loginName+"' ";
			System.out.println(sql);
			ResultSet rs=dao.selectData(sql);
			List<UserInfo> userInfoList=this.getListObjects(rs, UserInfo.class);
			if(userInfoList.size()==0) {
				strValue="errUser";//没有此用户
			}else {
					traversal:for(UserInfo userInfo:userInfoList) {
							if(userInfo.getPassWord()!=null
									&&userInfo.getPassWord().equals(passWord))	{
								session.setAttribute("loginAdmin", userInfo);
								strValue="loginSuc";//登录成功
								break traversal;
							}
					}
				
					if(!strValue.equals("loginSuc")) {
						strValue="errPassWord";
					}	
			}
		}else {
			strValue="errConnect";//数据库连接失败
		}
		dao.CloseCon();//关闭此次连接
		return strValue;
	}

 
}
